//
//  CompanyContentView.m
//  Btpin
//
//  Created by Vic on 2019/3/21.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "CompanyContentView.h"

@implementation CompanyContentView

- (instancetype)initWithFrame:(CGRect)frame info:(CompanyInfoModel *)model target:(nonnull id)target {
    self = [super initWithFrame:frame];
    if (self) {
        [self initUIWithInfo:model];
        self.delegate = target;
    }
    return self;
}
- (void)initUIWithInfo:(CompanyInfoModel *)model {
    UILabel *companyContentsTitleLbl = [UIToolsControl initLabelWithFrame:CGRectMake(0, 5*Scale, 200, 55*Scale) text:@"公司介绍" textColor:THEMECOLOR_OF_TEXT_333333 font:Font_20];
    [self addSubview:companyContentsTitleLbl];
    UIImageView *companyLogoImgView = [UIToolsControl initImageViewWithFrame:CGRectMake(0, EndY(companyContentsTitleLbl), 40*Scale, 40*Scale) imageName:@"logo_bg"];
    [self addSubview:companyLogoImgView];
    if (model.logo && model.logo.length) {
        [companyLogoImgView sd_setImageWithURL:[NSURL URLWithString:model.logo] placeholderImage:[UIImage imageNamed:@"logo_bg"]];
    }
    UILabel *companyFullNameLbl = [UIToolsControl initLabelWithFrame:CGRectMake(EndX(companyLogoImgView)+10*Scale, EndY(companyContentsTitleLbl), self.frame.size.width-70*Scale, 20*Scale) text:model.full_name textColor:THEMECOLOR_OF_TEXT_333333 font:Font_15];
    [self addSubview:companyFullNameLbl];
    UILabel *companyBaseInfoLbl = [UIToolsControl initLabelWithFrame:CGRectMake(StartX(companyFullNameLbl), EndY(companyFullNameLbl), ViewWidth(companyFullNameLbl), 20*Scale) text:[NSString stringWithFormat:@"%@ | %@ | %@", model.finance_cn, model.scale_cn, model.trade_cn] textColor:THEMECOLOR_OF_TEXT_666666 font:Font_13];
    [self addSubview:companyBaseInfoLbl];
    UIImageView *rightImgView1 = [UIToolsControl initImageViewWithFrame:CGRectMake(self.frame.size.width-10*Scale, 72*Scale, 7*Scale, 13*Scale) imageName:@"jiantou_right"];
    [self addSubview:rightImgView1];
    UILabel *jodAddressTitleLbl = [UIToolsControl initLabelWithFrame:CGRectMake(0, EndY(companyLogoImgView)+15*Scale, 100, 25*Scale) text:@"工作地址：" textColor:THEMECOLOR_OF_TEXT_333333 font:Font_13];
    [self addSubview:jodAddressTitleLbl];
    CGFloat addressWidth = [UIToolsControl textWidth:model.address size:CGSizeMake(MAXFLOAT, 25*Scale) font:Font_13]+10*Scale;
    UILabel *jodAddressLbl = [UIToolsControl initLabelWithFrame:CGRectMake(0, EndY(jodAddressTitleLbl), addressWidth, 30*Scale) text:model.address textColor:THEMECOLOR_OF_TEXT_666666 font:Font_13];
    [self addSubview:jodAddressLbl];
    UIImageView *addressImgView = [UIToolsControl initImageViewWithFrame:CGRectMake(EndX(jodAddressLbl), StartY(jodAddressLbl)+5*Scale, 13*Scale, 18*Scale) imageName:@"address_icon"];
    [self addSubview:addressImgView];
    
    UIButton *detailBtn = [UIToolsControl initButtonWithFrame:CGRectMake(0, 0, self.frame.size.width, 100*Scale) imageName:nil target:self action:@selector(detailBtnTap) title:nil titleColor:nil];
    [self addSubview:detailBtn];
    
    UIButton *addressBtn = [UIToolsControl initButtonWithFrame:CGRectMake(0, EndY(detailBtn), self.frame.size.width, 80*Scale) imageName:nil target:self action:@selector(addressBtnTap) title:nil titleColor:nil];
    [self addSubview:addressBtn];
}
- (void)detailBtnTap {
    if (self.delegate && [self.delegate respondsToSelector:@selector(companyContentViewOfDetailTap)]) {
        [self.delegate companyContentViewOfDetailTap];
    }
}
- (void)addressBtnTap {
    if (self.delegate && [self.delegate respondsToSelector:@selector(companyContentViewOfAddressTap)]) {
        [self.delegate companyContentViewOfAddressTap];
    }
}

@end
